package java6699.dao.gui;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;


public class Dialog6699Controller {
    private Student6699 student;

    @FXML
    private AnchorPane root;

    @FXML
    private TextField tfSno;

    @FXML
    private TextField tfSname;

    @FXML
    private TextField tfLx1;

    @FXML
    private TextField tfLx2;

    @FXML
    private Button btnYes;

    public Student6699 getStudent(){
        return student;
    }

    public void initAdd6699(){
        student =null;
        btnYes.setText("增加");
        tfSno.setText("");
        tfSname.setText("");
        tfLx1.setText("");
        tfLx2.setText("");
    }

    public void initChange6699(Student6699 student6699){
        student =null;
        btnYes.setText("修改");
        tfSno.setText(student6699.getSno());
        tfSname.setText(student6699.getSname());
        tfLx1.setText(student6699.getLx1()+"");
        tfLx2.setText(student6699.getLx2()+"");
    }


    @FXML
    void no(ActionEvent event) {
        ((Stage) root.getScene().getWindow()).close();
    }

    @FXML
    void yes(ActionEvent event) {
        //获取文本框中对应的数据
        String sno = tfSno.getText().trim();
        String sname = tfSname.getText().trim();
        if (sno.isEmpty() || sname.isEmpty()){
            new Alert(Alert.AlertType.ERROR,"学号和姓名不能为空").showAndWait();
            tfSno.requestFocus();
            return;
        }
        student =new Student6699(sno,sname);
        int lx1=0,lx2=0;
        try{
            lx1=Integer.parseInt(tfLx1.getText());
            lx2=Integer.parseInt(tfLx2.getText());
        }catch (Exception e){
        }
        student.setLx1(lx1);
        student.setLx2(lx2);
        ((Stage) root.getScene().getWindow()).close();
    }


}
